package com.leetCode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-11 11:16:03
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-11     张李鑫                     1.0         1.0 Version
 */
public class TowSearch {


    public static int search(int[] nums, int target) {
        if (nums.length < 2) {
            return nums[0] == target ? 0 : -1;
        }
        int left = 0;
        int right = nums.length - 1;

        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] > target) {
                right = mid - 1;
            } else if (nums[mid] < target) {
                left = mid + 1;
            }else if (nums[mid]==target){
                return mid;
            }
        }
        return nums[left]==target?left:-1;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{2,5};
        int search = search(arr, 5);
        System.out.println(search);


    }
}
